package com.kaka.bus.engine.rechange;

import com.kaka.bus.bean.BankBean;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.bean.PayBean;
import com.kaka.bus.bean.Single;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.engine.common.impl.LoanService;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

/**
 * Created by OnionMac on 2018/7/11.
 */

public class RechangePresenter extends RxPresenter<RechangeContract.View> implements RechangeContract.Presenter {

    private LoanService mLoanService;

    @Inject
    public RechangePresenter(DataManager dataManager, LoanService loanService) {
        super(dataManager);
        mLoanService = loanService;
        setService(mLoanService);
    }

    @Override
    public void getBankList() {
        mLoanService.getBankList(new Result<HttpWrapper<List<BankBean>>>() {
            @Override
            protected void onSuccess(HttpWrapper<List<BankBean>> wrapper) {
                mView.getBankListSuccess(wrapper);
            }
        });
    }

    @Override
    public void getPayInfo(String userId, String token) {
        mView.showDialog(Constant.LOAD);
        addSubscribe(mDataManager
                .getApi()
                .getPayInfo(userId, token)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<PayBean>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<PayBean> wrapper) {
                        mView.getPayInfoS(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void pay(Map<String, String> map) {
        mView.showDialog("正在支付...");
        addSubscribe(mDataManager.getApi()
                .pay(map)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> wrapper) {

                        mView.payS(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }

    @Override
    public void getPayCode(String phone, String tokenKey, String senddynamic, String platform, String bankCard) {
        mView.showDialog("发送验证码");
        addSubscribe(mDataManager
                .getApi()
                .getPayCode(phone, tokenKey, senddynamic, platform, bankCard)
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<Single>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<Single> wrapper) {
                        mView.sendYzmS(wrapper);
                    }

                    @Override
                    protected void onFinish() {
                        super.onFinish();
                        mView.dissDialog();
                    }
                }));
    }


}
